package com.GUI.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestAction {
    public static void main(String[] args) {
        //按下按钮触发一些事件
        Frame frame = new Frame("TestAction事件监听");
        Button button = new Button("button1");

        //addActionListener()需要一个ActionListener，所以我们需要构造一个ActionListener
        MyActionListener myActionListener = new MyActionListener();
        button.addActionListener(myActionListener);


        frame.add(button);
        //设置可见
        frame.setVisible(true);
        //设置大小
        frame.setSize(500,400);
        //关闭
        windowsClose(frame);


    }
    //关闭方法
    private static void windowsClose(Frame frame) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
class  MyActionListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("aaa");
    }
}


